package com.jcgyl.export.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jcgyl.export.entity.Tbpayinfo;
import com.jcgyl.export.entity.Tbreceipt;
import com.jcgyl.export.model.payinfo.PayInfoModel;
import com.jcgyl.export.model.payinfo.ReceiptModel;
import com.jcgyl.export.service.PayInfoService;
import com.jcgyl.export.util.entity.JsonResult;
import com.jcgyl.export.util.entity.JsonUtil;
import com.jcgyl.export.util.entity.PageResult;

@Controller
@RequestMapping("/payinfo/")
public class PayinfoController {
	@Autowired
	private PayInfoService payInfoService;
	@GetMapping("query")
	public String Query() {
		return "payinfo/query";
	}
	/**
	 * 根据条件查询数据
	 * @param payInfoModel 
	 * @return
	 * JL
	 */
	@RequestMapping("doFindObject")
	@ResponseBody()
	public PageResult doFindObject(@RequestBody PayInfoModel payInfoModel) {
		//获取前端传入的数据
		String guid = payInfoModel.getFilter().getGuid();
		String orderid = payInfoModel.getFilter().getOrderid();
		String Starttime = payInfoModel.getFilter().getStart();
		String Endtime  = payInfoModel.getFilter().getEnd();
		Integer pageSize = payInfoModel.getPageSize();
		Integer pageCount = payInfoModel.getPageIndex();
		List<Map<String,Object>>list = payInfoService.findObject(guid, orderid, Starttime,Endtime, pageSize, pageCount);
		Integer row = payInfoService.getRowCount(guid, orderid, Starttime,Endtime);
		PageResult jsonResult = new PageResult();
		jsonResult.setTotalRows(row);
		jsonResult.setResult(list);
		return jsonResult;
	}
	/**
	 * 修改支付单数据
	 * @param tbpayinfo
	 * @return
	 * JL
	 */
	@RequestMapping("doUpdateObject")
	@ResponseBody
	public JsonResult doUpdateObject(@RequestBody Tbpayinfo tbpayinfo) {
		int row =payInfoService.UpdataObject(tbpayinfo);
		if(row !=1){
			return JsonUtil.error(1, "修改订单失败！");
		}else{
			return JsonUtil.success(row);
		}
	}
	/**
	 * 支付单回执查询
	 * @param receiptModel 前段传值
	 * @return
	 * JL
	 */
	@RequestMapping("doFindReceipt")
	@ResponseBody
	public JsonResult doFindReceipt(@RequestBody ReceiptModel receiptModel) {
		//获取支付单号
		String expressnumber = receiptModel.getGuid();
		System.out.println(expressnumber);
		//支付单回执码
		String receipttype = "IEPT201_BACK";
		List<Tbreceipt> list = payInfoService.findReceipt(receipttype, expressnumber);
		if(list.size() == 0){
			return JsonUtil.error(1, "暂无支付单回执信息！");
		}else{
			return JsonUtil.success(list);
		}
	}
}
